{extend name="../layout/base"}

{block name="body"}
<div class="login">
    <form class="layui-form layui-form-pane" action="" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label">账号</label>
            <div class="layui-input-block">
                <input type="text" name="username" required lay-verify="required" placeholder="请输入正确手机账号"  autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="sub">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                <div class="forget-password">
                    <a href="{$official_href}" target="_blank">没有账号？去注册一个</a>|
                    <a href="{$official_href}/user/auth/forget" target="_blank">找回密码</a>
                </div>
            </div>
        </div>
    </form>
</div>

<script>
    layui.use('form', function () {
        var form = layui.form;
        form.on('submit(sub)', function (data) {
            var loadingIndex = layer.load(1);
            $.post("{:url('login')}", data.field, function (res) {
                layer.close(loadingIndex);
                if(res.code === 1){
                    layer.msg(res.msg, {time: 1500}, function () {
                         location.href="{:url('index')}";
                    });
                }else{
                    layer.alert(res.msg);
                }
            }).error(function (error) {
                layer.alert('500 Internal Server Error');
                layer.close(loadingIndex)
            });
            return false;
        });
    });
</script>
{/block}

{block name="css"}
<style>
    .login{margin-top: 50px;}
    .forget-password{font-size: 12px;display: inline-block;margin-left: 30px;}
    .forget-password a{padding-left: 5px;padding-right: 5px;}
</style>
{/block}